from device import Device
'''
==============================================================
不能直接赋值前方未定义的变量
temperature=thermometer.Get_Temperature()  错误的
--------------------------------------------------------------
temperature=None
temperature=thermometer.Get_Temperature()  正确的
==============================================================
禁止使用对象的属性赋值给变量，必须使用函数调用
temperature=thermometer.Temperature  错误的
--------------------------------------------------------------
temperature=thermometer.Get_Temperature()  正确的
==============================================================
运算不能使用缩写
a+=1 错误的
--------------------------------------------------------------
a=a+1 正确的
==============================================================
循环不能直接1
while 1: 错误的
    xxx
--------------------------------------------------------------
while 1==1:正确的
    xxx
==============================================================
'''

'''
温控
# 初始化最高温度
maxTemp = 25
minTemp= 18
Temp=None
# 初始化温度计
tempDevice = Device(device_id=0)
# 初始化空调
coldAir = Device(device_id=1)
HotAir = Device(device_id=2)
# 设置空调开关
coldAir.On = 0
HotAir.On = 0
while 1==1:
    Temp = tempDevice.Get_temperature()
    if Temp > maxTemp:
        HotAir.On = 0
        coldAir.On = 1
    else:
        HotAir.On = 1
        coldAir.On = 0
'''

outdoor=Device(device_id=0)#外门
indoor=Device(device_id=1)#内门
outAir=Device(device_id=2)#外门气闸
inAir=Device(device_id=3)#内门气闸

baShou=Device(device_id=4)#开关
AirThink=Device(device_id=5)#气体传感器

NowPress=None
NowOpen=None
outdoor.On = 0
indoor.On = 0
outAir.On = 0
inAir.On = 0
while 1==1:
    NowPress=AirThink.Get_pressure()
    NowOpen=baShou.Get_On()
    if NowOpen==0:# 开关关闭,外门关闭，外门气闸打开,进气闸房间
        if NowPress==0:# 如果气闸房间的气压已经抽空
            outdoor.On = 0
            indoor.On = 1
            outAir.On = 0
            inAir.On = 0
        else:#气闸房间的气压未抽空
            outdoor.On = 0
            indoor.On = 0
            outAir.On = 1
            inAir.On = 0
    else:# 开关打开,外门打开，外门气闸关闭,出气闸房间，内门关闭，外门气闸打开
        if NowPress==0:# 如果气闸房间的气压已经抽空
            outdoor.On = 1
            indoor.On = 0
            outAir.On = 0
            inAir.On = 0
        else:#气闸房间的气压未抽空
            outdoor.On = 0
            indoor.On = 0
            outAir.On = 0
            inAir.On = 1
